/*
 * This file is part of GuitarMaster.
 * 
 * GuitarMaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GuitarMaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.paris5.master2.guitarmaster.entity;

import com.paris5.master2.guitarmaster.bean.EcomStore;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Leticia Mahamed, Alice Khammy, mourad nedjahi, Saliou Mamadou Barry
 */
@Entity
@Table(name = "store")
public class Store implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_store")
    private Integer idStore;
   
    @Size(max = 65535)
    @Column(name = "adresse", length = 65535)
    private String adresse;
    
    @Size(max = 100)
    @Column(name = "name", length = 100)
    private String name;
    
    @Column(name = "latitude")
    private Integer latitude;
    
    @Column(name = "longetude")
    private Integer longetude;

    @JoinColumn(name = "code", referencedColumnName = "code", nullable = false)
    @ManyToOne(optional = false)
    private Country code;
    
    @Column(name = "balance")
    private Float balance;

    public Store() {
    }
    
    public Store(EcomStore es){
        idStore = es.getIdStore();
        adresse = es.getAdresse();
        name = es.getName();
        latitude = es.getLatitude();
        longetude = es.getLongetude();
        balance=es.getBalance();
        code = new Country(es.getCode());
        
    }
    
    public EcomStore getEcomStore(){
        EcomStore ecs = new EcomStore();
         ecs.setIdStore(idStore);
         ecs.setAdresse(adresse);
         ecs.setName(name);
         ecs.setLatitude(latitude);
         ecs.setLongetude(longetude);
         ecs.setCode(code.getEcomCountry());
         ecs.setBalance(balance);
         return ecs;
    }

    public Store(Integer idStore) {
        this.idStore = idStore;
    }

    public Integer getIdStore() {
        return idStore;
    }

    public void setIdStore(Integer idStore) {
        this.idStore = idStore;
    }

    public String getAdresse() {
        return adresse;
    }

    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getLatitude() {
        return latitude;
    }

    public void setLatitude(Integer latitude) {
        this.latitude = latitude;
    }

    public Integer getLongetude() {
        return longetude;
    }

    public void setLongetude(Integer longetude) {
        this.longetude = longetude;
    }

    public Country getCode() {
        return code;
    }

    public void setCode(Country code) {
        this.code = code;
    }

    public void setBalance(Float balance) {
        this.balance = balance;
    }

    public Float getBalance() {
        return balance;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idStore != null ? idStore.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Store)) {
            return false;
        }
        Store other = (Store) object;
        if ((this.idStore == null && other.idStore != null) || (this.idStore != null && !this.idStore.equals(other.idStore))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.paris5.master2.guitarmaster.entity.Store[ idStore=" + idStore + " ]";
    }
    
}
